import time
import vec

WIDTH = 250
HEIGHT = 250

BackColor = (0, 0, 127)
CircleColor = (0, 200, 0)

LastTime = time.time()

class Circle:
    def __init__(self, pos, r):
        self.pos = pos
        self.r = r

    def Draw(self):
        screen.draw.filled_circle((self.pos.x, self.pos.y), self.r, CircleColor)


def on_key_down(key):
    if key == keys.ESCAPE:
        quit()

Start = vec.Vec2(50, 50)
Target = vec.Vec2(200, 200)
FullLength = (Target - Start).length()
c = Circle(Start, 30)
s = int(input("speed: "))
RoadDir = Target - c.pos
RoadDir.normalize()
IsMoving = True
MoveDir = Target - Start
MoveDir.normalize()

def update():
    global IsMoving, LastTime
    if IsMoving == False:
        return

    MovedLength = (c.pos - Start).length()

    CurTime = time.time()
    dt = CurTime - LastTime
    LastTime = CurTime
    if MovedLength < FullLength:
        c.pos = c.pos + MoveDir * s * dt
    else:
        c.pos = Target
        IsMoving = False

def draw():
    screen.fill(BackColor)
    c.Draw()
